package com.ks.user.controller;


import com.ks.core.base._ControllerBase;
import com.ks.core.core.Result;
import com.ks.core.dto.SearchCriteriaBase;
import com.ks.user.controller.dto.EmployeeRequest;
import com.ks.user.controller.dto.OrgBaseRequest;
import com.ks.user.controller.dto.TenantRequest;
import com.ks.user.entity.OrgBase;
import com.ks.user.entity.OrgEmployee;
import com.ks.user.entity.OrgTenant;
import com.ks.user.entity.UserBase;
import com.ks.user.service.IOrgBaseService;
import com.ks.user.service.IOrgEmployeeService;
import com.ks.user.service.IOrgTenantService;
import com.ks.user.service.IUserBaseService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 组织机构表 前端控制器
 * </p>
 *
 * @author kingdee123
 * @since 2020-11-30
 */
@RestController
@RequestMapping("/orgBase")
@Api(value = "组织机构模块", description = "组织机构模块")
public class OrgBaseController extends _ControllerBase {

    @Autowired
    private IOrgBaseService orgBaseService;

    @Autowired
    private IOrgEmployeeService orgEmployeeService;

    @Autowired
    private IOrgTenantService orgTenantService;


    @PostMapping("/getOrgBaseList")
    @ApiOperation(value = "租户的组织信息获取接口", notes = "租户的组织信息获取接口")
    public Object getOrgBaseList(@RequestBody SearchCriteriaBase searchCriteriaBase) {
        Map<String, Object> orgBaseList = orgBaseService.getOrgBaseList(getContext(),searchCriteriaBase);
        return Result.success(orgBaseList);
    }

    @PostMapping("/getList")
    @ApiOperation(value = "租户组织列表", notes = "租户组织列表")
    public Object getBaseList() {
        List<OrgBase> list = orgBaseService.getList(getContext());
        return Result.success(list);
    }


    @PostMapping("/setTenantAdmin")
    @ApiOperation(value = "设置租户管理员", notes = "设置租户管理员")
    public Object setTenantAdmin(@RequestBody TenantRequest request) {
        int i = orgBaseService.setTenantAdmin(getContext(), request.getTenantId());
        return Result.success(i);
    }

    @PostMapping("/getTenantList")
    @ApiOperation(value = "租户申请列表查询接口", notes = "租户申请列表查询接口")
    public Object getTenantList(@RequestBody SearchCriteriaBase searchCriteriaBase) {
        Map<String, Object> tenantList = orgTenantService.getTenantList(getContext(), searchCriteriaBase);
        return Result.success(tenantList);
    }

    @PostMapping("/delTenant")
    @ApiOperation(value = "删除租户入驻信息", notes = "删除租户入驻信息")
    public Object delTenant(@RequestBody OrgTenant orgTenant) {
        int i = orgTenantService.delOrgTenantInfo(getContext(), orgTenant);
        return Result.success(i);
    }

    @PostMapping("/setTenantState")
    @ApiOperation(value = "租户审核接口", notes = "租户审核接口")
    public Object setTenantState(@RequestBody TenantRequest request) {
        int i = orgTenantService.examineTenant(getContext(), request.getTenantId(), request.getStatus(), request.getTenantCode(), request.getRemark());
        return Result.success(i);
    }


    @PostMapping("/TenantOpen")
    @ApiOperation(value = "开启租户服务,关闭租户服务", notes = "开启租户服务,关闭租户服务")
    public Object setTenantOpen(@RequestBody OrgBaseRequest request) {
        int i = orgBaseService.updateTenantServiceStatus(request.getTenantId(), request.getServiceStatus());
        return Result.success(i);
    }

    @PostMapping("/addOrgBase")
    @ApiOperation(value = "组织机构添加接口", notes = "组织机构添加接口")
    public Object addOrgBase(@RequestBody OrgBase orgBase) {
        int i = orgBaseService.addOrgBase(getContext(), orgBase);
        return Result.success(i);
    }

    @PostMapping("/getTree")
    @ApiOperation(value = "获取组织树结构", notes = "获取组织树结构")
    public Object getTreeList(@RequestBody OrgBaseRequest request) {
        Map<String, Object> tree = orgBaseService.getTree(request.getTenantId());
        return Result.success(tree);
    }

    @PostMapping("/updateOrgBase")
    @ApiOperation(value = "组织机构修改接口", notes = "组织机构修改接口")
    public Object updateOrgBase(@RequestBody OrgBase orgBase) {
        int i = orgBaseService.updateOrgBase(getContext(), orgBase);
        return Result.success(i);
    }


    @PostMapping("/addOrgEmployee")
    @ApiOperation(value = "组织机构员工添加接口", notes = "组织机构员工添加接口")
    public Object addOrgEmployee(@RequestBody OrgEmployee orgEmployee) {
        int i = orgEmployeeService.addOrgEmployee(getContext(), orgEmployee);
        return Result.success(i);
    }

    @PostMapping("/updateOrgEmployee")
    @ApiOperation(value = "组织机构员工修改接口", notes = "组织机构员工修改接口")
    public Object updateOrgEmployee(@RequestBody OrgEmployee orgEmployee) {
        int i = orgEmployeeService.updateOrgEmployee(getContext(), orgEmployee);
        return Result.success(i);
    }


}

